package com.nhxcz.bigdataweb.controller;

import com.nhxcz.bigdataweb.entity.History;
import com.nhxcz.bigdataweb.entity.YiChangPoint;
import com.nhxcz.bigdataweb.mapper.YCJJMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;

@RestController
public class YCJJController {

    @Autowired
    private YCJJMapper ycjjmapper; // 没有必要为了分层强行使用ycjjService

    @GetMapping("/AbnormalPoints")
    public ArrayList<YiChangPoint> getAbnormalPoints() {
        System.out.println(new Date() + "  getAbnormalPoints");
        return ycjjmapper.getAllPoints();
    }

    @GetMapping("/History")
    public ArrayList<History> getHistory(@Param("longitude")double longitude, @Param("longitude")double latitude) {
        System.out.println(new Date() + "  getHistory");
        ArrayList<History> historys = ycjjmapper.getHistory(longitude, latitude);
        for (int i = 0; i < historys.size(); i++) {
            historys.get(i).setTime(historys.get(i).getTime().substring(8, 10) + ":" + historys.get(i).getTime().substring(10, 12));
        }
        return historys;
    }

}
